import request from '@/utils/request'

//登录
export function login(data) {
  return request({
    url: '/login',
    method: 'post',
    data: data
  })
}

// 登出
export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 注册
export function reg(data) {
  return request({
    url: '/reg',
    method: 'post',
    data: data
  })
}

// 用户

export function getInfo() {
  return request({
    url: '/user/getLoginUserVOById',
  })
}

export function getByCurrentUser() {
  return request({
    url: '/user/getByCurrentUser',
  })
}

export function updatePassword(data) {
  return request({
    url: `/user/updatePassword`,
    method: "post",
    data: data
  })
}

export function getUserByPage(data) {
  return request({
    url: '/user',
    params: { ...data }
  })
}

export function getUserById(id) {
  return request({
    url: `/user/${id}`
  })
}

export function updateUserById(data) {
  return request({
    url: `/user`,
    method: "put",
    data: data
  })
}

export function deleteUser(id) {
  return request({
    url: `/user/${id}`,
    method: 'delete',
  })
}

export function batchDeleteUser(idList) {
  return request({
    url: `/user/batchDeleteUser`,
    method: 'post',
    data: idList
  })
}

export function addUser(data) {
  return request({
    url: '/user',
    method: 'post',
    data: data
  })
}

export function setRoles(id,data) {
  return request({
    url: `/user/setRoles/${id}`,
    method: 'post',
    data: data
  })
}

// 角色

export function geRoleByPage(data) {
  return request({
    url: '/role',
    params: { ...data }
  })
}

export function getRoleById(id) {
  return request({
    url: `/role/${id}`,
  })
}

export function addRole(data) {
  return request({
    url: '/role',
    method: 'post',
    data: data
  })
}

export function updateRoleById(data) {
  return request({
    url: `/role`,
    method: 'put',
    data: data
  })
}

export function deleteRole(id) {
  return request({
    url: `/role/${id}`,
    method: 'delete',
  })
}

export function batchDeleteRole(idList) {
  return request({
    url: `/role/batchDeleteRole`,
    method: 'post',
    data: idList
  })
}

export function setPermissions(id,idList) {
  return request({
    url: `/role/setPermissions/${id}`,
    method: 'post',
    data: idList
  })
}

// 权限

export function addPermission(data) {
  return request({
    url: '/permission',
    method: 'post',
    data: data
  })
}

export function getPermissionByPage(data) {
  return request({
    url: '/permission',
    params: { ...data }
  })
}

export function getPermissionById(id) {
  return request({
    url: `/permission/${id}`,
  })
}

export function getPermissionTreeList() {
  return request({
    url: `/permission/treeList`,
  })
}

export function deletePermission(id) {
  return request({
    url: `/permission/${id}`,
    method: 'delete'
  })
}

export function batchDeletePermission(idList) {
  return request({
    url: `/permission/batchDeletePermission`,
    method: 'post',
    data: idList
  })
}

export function updatePermissionById(data) {
  return request({
    url: `/permission`,
    method: 'put',
    data: data
  })
}

export function getPermissionByLevel(level) {
  return request({
    url: `/permission/getByLevel/${level}`,
  })
}

export function getPermissionByRoleId(id) {
  return request({
    url: `/permission/getByRoleId/${id}`,
  })
}
